package com.battery.web.controller.system.battery;

import java.util.List;

import com.battery.system.domain.BO.PointsDetailBO;
import com.battery.system.domain.VO.PointsDetailVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.battery.common.annotation.Log;
import com.battery.common.enums.BusinessType;
import com.battery.system.domain.PointsDetail;
import com.battery.system.service.IPointsDetailService;
import com.battery.common.core.controller.BaseController;
import com.battery.common.core.domain.AjaxResult;
import com.battery.common.utils.poi.ExcelUtil;
import com.battery.common.core.page.TableDataInfo;

/**
 * 积分流水Controller
 *
 * @author battery
 * @date 2021-03-24
 */
@Controller
@RequestMapping("/system/pointsDetail")
public class PointsDetailController extends BaseController {
    private String prefix = "system/pointsDetail";

    @Autowired
    private IPointsDetailService pointsDetailService;

    @RequiresPermissions("system:pointsDetail:view")
    @GetMapping()
    public String pointsDetail() {
        return prefix + "/pointsDetail";
    }

    /**
     * 查询积分流水列表
     */
    @RequiresPermissions("system:pointsDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointsDetailBO pointsDetailBO) {
        startPage();
//        List<PointsDetail> list = pointsDetailService.selectPointsDetailList(pointsDetail);
        List<PointsDetailVO> list = pointsDetailService.selectPointsDetailVOList(pointsDetailBO);
        return getDataTable(list);
    }

    /**
     * 导出积分流水列表
     */
    @RequiresPermissions("system:pointsDetail:export")
    @Log(title = "积分流水" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PointsDetail pointsDetail) {
        List<PointsDetail> list = pointsDetailService.selectPointsDetailList(pointsDetail);
        ExcelUtil<PointsDetail> util = new ExcelUtil<PointsDetail>(PointsDetail.class);
        return util.exportExcel(list, "pointsDetail");
    }

    /**
     * 新增积分流水
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存积分流水
     */
    @RequiresPermissions("system:pointsDetail:add")
    @Log(title = "积分流水" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PointsDetail pointsDetail) {
        return toAjax(pointsDetailService.insertPointsDetail(pointsDetail));
    }

    /**
     * 修改积分流水
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        PointsDetail pointsDetail = pointsDetailService.selectPointsDetailById(id);
        mmap.put("pointsDetail" , pointsDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存积分流水
     */
    @RequiresPermissions("system:pointsDetail:edit")
    @Log(title = "积分流水" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PointsDetail pointsDetail) {
        return toAjax(pointsDetailService.updatePointsDetail(pointsDetail));
    }

    /**
     * 删除积分流水
     */
    @RequiresPermissions("system:pointsDetail:remove")
    @Log(title = "积分流水" , businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(pointsDetailService.deletePointsDetailByIds(ids));
    }
}
